package codetop.microsoft.T621;

import java.util.Arrays;

/**
 * @Author: 18362
 * @Create: 2022-08-16 17:03:32 星期二
 */
class Solution {
    public int leastInterval(char[] tasks, int n) {
        int[] cnt = new int[26];
        for (int i=0; i<tasks.length; ++i)
            cnt[tasks[i] - 'A']++;
        Arrays.sort(cnt);
        int num = 0;
        for (int i=0; i<cnt.length; ++i) {
            if (cnt[i] == cnt[cnt.length-1])
                num++;
        }
        return Math.max(tasks.length, (cnt[cnt.length-1]-1)*(n+1)+num);
    }
}